package Hibernate.manytomany;


import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import java.util.Set;

public class UserAction  {
    private Session session;
    public static void main(String[] args)throws Exception  {
        SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
       Session session = sessionFactory.openSession();

        Transaction transaction = session.beginTransaction();
            User user1 = new User();
            user1.setName("小明");
        User user2= new User();
        user2.setName("华军");
        Class1 class1 = new Class1();
        Class1 class2 = new Class1();
        Class1 class3 = new Class1();
        class3.setCname("工商管理");
        class2.setCname("计算机科学与技术");
        class1.setCname("电子科技");
        //class1.getUser().add(user1);
       // user2.setClass1(class1);
        ///class1.getUser().add(user2);
            

        session.save(class1);
       // session.save(class2);
        //session.save(class3);
       // session.save(user1);
        //session.save(user2);
        //session.save(user2);


        transaction.commit();
            session.close();
        }
    }
